<template>
  <base-content>
    <template>
      <sf-grid ref="grid" :columns="columns" :store-config="configs" />
    </template>
  </base-content>
</template>

<script>
import { mapGetters } from 'vuex'
import { getRecordList } from '@/api/coupon'
import { queryParams } from '@/utils'

export default {
  data() {
    return {
      // here is table
      columns: [
        {
          title: '优惠卷id',
          props: 'coupon_id'
        },
        {
          title: '优惠卷名称',
          props: 'coupon_name'
        },
        {
          title: '使用时间',
          props: 'insert_time'
        },
        {
          title: '订单id',
          props: 'order_id'
        },
        {
          title: '用户id',
          props: 'user_id'
        },
        {
          title: '使用途径',
          formatter(val) {
            const { order_type } = val
            const statusT = { 1: '普通订单', 2: '拼团订单' }
            return statusT[order_type]
          }
        }
      ],
      formData: {},
      configs: {
        loadDataApi: function (p) {
          return new Promise((resolve) => {
            getRecordList(queryParams(p, this.formData)).then((res) => {
              resolve(res)
            })
          })
        },
        fetchListData: function (res) {
          return res.info.data
        },
        fetchTotal: function (res) {
          return res.info.meta.count
        },
        generateQueryParams: function (pagination) {
          const { pageIndex, pageSize } = pagination
          return {
            page_num: pageIndex,
            page_size: pageSize
          }
        }
      }
    }
  },
  computed: {
    ...mapGetters(['sidebar']),
    routes() {
      return this.$router.options.routes
    }
  },
  methods: {
    handleAdd() {
      this.isShow = true
    },
    // val: 当前表单中的数据
    // key 用来handles 中设置的唯一标识key值
    handleBaseSearch(val, key) {
      if (key === 'search') {
        alert(JSON.stringify(val))
      } else if (key === 'add') {
        this.isShow = true
      } else {
        const formEle = this.$refs.baseSearchEle
        formEle.empty()
      }
    }
  }
}
</script>
